using FluentValidation;

namespace Application.Todos.Update;

internal sealed class UpdateTodoCommandValidator : AbstractValidator<UpdateTodoCommand>
{
    public UpdateTodoCommandValidator()
    {
        RuleFor(x => x.TodoItemId)
            .NotEmpty()
            .WithMessage("Todo item ID is required");

        RuleFor(x => x.Description)
            .NotEmpty()
            .WithMessage("Description is required")
            .MaximumLength(500)
            .WithMessage("Description cannot exceed 500 characters");

        RuleFor(x => x.Priority)
            .IsInEnum()
            .WithMessage("Invalid priority value");

        RuleFor(x => x.DueDate)
            .GreaterThan(DateTime.UtcNow.AddMinutes(-1))
            .When(x => x.DueDate.HasValue)
            .WithMessage("Due date cannot be in the past");

        RuleForEach(x => x.Labels)
            .NotEmpty()
            .WithMessage("Label cannot be empty")
            .MaximumLength(50)
            .WithMessage("Label cannot exceed 50 characters")
            .When(x => x.Labels is not null);
    }
}